# eric7.MicroPython.Devices.CircuitPythonDevices

Module implementing the device interface class for CircuitPython boards.

### Global Attributes

None

### Classes

CircuitPythonDevice | Class implementing the device for CircuitPython boards.

### Functions

createDevice | Function to instantiate a MicroPython device object.

## CircuitPythonDevice

Class implementing the device for CircuitPython boards.

### Derived from

BaseDevice

### Class Attributes

DeviceVolumeName

### Class Methods

None

### Methods

CircuitPythonDevice | Constructor
__aboutToShowLibraryMenu | Private slot to populate the 'Library Management' menu.
__activateBootloader | Private slot to switch the board into 'bootloader' mode.
__activateUF2Boot | Private slot to switch the board into 'UF2 Boot' mode.
__cpyVersionResponse | Private slot handling the response of the latest version request.
__createCPyMenu | Private method to create the CircuitPython submenu.
__createFlashMenus | Private method to create the various menus to flash a CircuitPython firmware.
__deviceVolumeMounted | Private method to check, if the device volume is mounted.
__esp32EraseFlash | Private slot to erase the flash of an ESP32 device.
__esp32FlashAddons | Private slot to flash additional firmware to an ESP32 device.
__esp32FlashPython | Private slot to flash a MicroPython or CircuitPython firmware to an ESP32 device.
__findDeviceDirectories | Private method to find the device directories associated with the current board name.
__findWorkspace | Private method to find the workspace directory.
__flashCircuitPython | Private slot to flash a CircuitPython firmware to a device supporting UF2.
__installLibraryFiles | Private slot to install Python files into the onboard library.
__modifySettings | Private method to modify the 'settings.toml' file as of CircuitPython 8.0.0.
__resetDevice | Private slot to reset the connected device.
__selectDeviceVolume | Private slot to select the mounted device volume, if it could not be found automatically.
__showTeensyFlashInstructions | Private slot to show a message box because Teensy does not support the UF2 bootloader yet.
__startTeensyLoader | Private slot to start the 'Teensy Loader' application.
activateBluetoothInterface | Public method to activate the Bluetooth interface.
addDeviceMenuEntries | Public method to add device specific entries to the given menu.
canRunScript | Public method to determine, if a script can be executed.
canStartFileManager | Public method to determine, if a File Manager can be started.
canStartPlotter | Public method to determine, if a Plotter can be started.
canStartRepl | Public method to determine, if a REPL can be started.
checkInternet | Public method to check, if the internet can be reached.
checkInternetViaLan | Public method to check, if the internet can be reached (LAN variant).
connectToLan | Public method to connect the connected device to the LAN.
connectWifi | Public method to connect a device to a WiFi network.
deactivateBluetoothInterface | Public method to deactivate the Bluetooth interface.
deactivateEthernet | Public method to deactivate the Ethernet interface of the connected device.
deactivateInterface | Public method to deactivate a given WiFi interface of the connected device.
deviceName | Public method to get the name of the device.
disconnectFromLan | Public method to disconnect from the LAN.
disconnectWifi | Public method to disconnect a device from the WiFi network.
forceInterrupt | Public method to determine the need for an interrupt when opening the serial connection.
getBluetoothStatus | Public method to get Bluetooth status data of the connected board.
getConnectedClients | Public method to get a list of connected clients.
getDeviceScan | Public method to perform a Bluetooth device scan.
getDocumentationUrl | Public method to get the device documentation URL.
getDownloadMenuEntries | Public method to retrieve the entries for the downloads menu.
getEthernetStatus | Public method to get Ethernet status data of the connected board.
getSecurityModes | Public method to get a list of security modes supported by the device.
getWifiData | Public method to get data related to the current WiFi status.
getWorkspace | Public method to get the workspace directory.
hasBluetooth | Public method to check the availability of Bluetooth.
hasEthernet | Public method to check the availability of Ethernet.
hasFlashMenuEntry | Public method to check, if the device has its own flash menu entry.
hasNetworkTime | Public method to check the availability of network time functions.
hasWifi | Public method to check the availability of WiFi.
isLanConnected | Public method to check the LAN connection status.
isWifiApConnected | Public method to check the WiFi connection status as access point.
isWifiClientConnected | Public method to check the WiFi connection status as client.
removeCredentials | Public method to remove the saved credentials from the connected device.
removeLanAutoConnect | Public method to remove the saved IPv4 parameters from the connected device.
runScript | Public method to run the given Python script.
scanNetworks | Public method to scan for available WiFi networks.
setButtons | Public method to enable the supported action buttons.
setConnected | Public method to set the connection state.
setNetworkTime | Public method to set the time to the network time retrieved from an NTP server.
setWorkspace | Public method to set the device workspace directory.
showCircuitPythonVersions | Public slot to show the CircuitPython version of a connected device and the latest available one (from Github).
startAccessPoint | Public method to start the access point interface.
stopAccessPoint | Public method to stop the access point interface.
supportsDeviceScan | Public method to indicate, that the Bluetooth implementation supports scanning for devices.
supportsLocalFileAccess | Public method to indicate file access via a local directory.
writeCredentials | Public method to write the given credentials to the connected device and modify the start script to connect automatically.
writeLanAutoConnect | Public method to generate a script and associated configuration to connect the device to the LAN during boot time.

### Static Methods

None

#### CircuitPythonDevice (Constructor)

CircuitPythonDevice(microPythonWidget, deviceType, boardName, vid=0, pid=0, hasWorkspace=True, parent=None, )

Constructor

microPythonWidget (MicroPythonWidget)
  reference to the main MicroPython widget
deviceType (str)
  device type assigned to this device interface
boardName (str)
  name of the board
vid (int (optional))
  vendor ID (defaults to 0)
pid (int (optional))
  product ID (defaults to 0)
hasWorkspace (bool (optional))
  flag indicating that the devices supports access via a mounted volume (defaults to True)
parent (QObject)
  reference to the parent object

#### CircuitPythonDevice.__aboutToShowLibraryMenu

__aboutToShowLibraryMenu()

Private slot to populate the 'Library Management' menu.

#### CircuitPythonDevice.__activateBootloader

__activateBootloader()

Private slot to switch the board into 'bootloader' mode.

#### CircuitPythonDevice.__activateUF2Boot

__activateUF2Boot()

Private slot to switch the board into 'UF2 Boot' mode.

#### CircuitPythonDevice.__cpyVersionResponse

__cpyVersionResponse(reply)

Private slot handling the response of the latest version request.

reply (QNetworkReply)
  reference to the reply object

#### CircuitPythonDevice.__createCPyMenu

__createCPyMenu()

Private method to create the CircuitPython submenu.

#### CircuitPythonDevice.__createFlashMenus

__createFlashMenus()

Private method to create the various menus to flash a CircuitPython firmware.

Return:
  reference to the created top level flash menu

Return Type:
  QMenu

#### CircuitPythonDevice.__deviceVolumeMounted

__deviceVolumeMounted()

Private method to check, if the device volume is mounted.

Return:
  flag indicated a mounted device

Return Type:
  bool

#### CircuitPythonDevice.__esp32EraseFlash

__esp32EraseFlash()

Private slot to erase the flash of an ESP32 device.

#### CircuitPythonDevice.__esp32FlashAddons

__esp32FlashAddons()

Private slot to flash additional firmware to an ESP32 device.

#### CircuitPythonDevice.__esp32FlashPython

__esp32FlashPython()

Private slot to flash a MicroPython or CircuitPython firmware to an ESP32 device.

#### CircuitPythonDevice.__findDeviceDirectories

__findDeviceDirectories(directories)

Private method to find the device directories associated with the current board name.

directories (list of str)
  list of directories to be checked

Return:
  list of associated directories

Return Type:
  list of str

#### CircuitPythonDevice.__findWorkspace

__findWorkspace(silent=False)

Private method to find the workspace directory.

silent (bool (optional))
  flag indicating silent operations (defaults to False)

Return:
  workspace directory used for saving files

Return Type:
  str

#### CircuitPythonDevice.__flashCircuitPython

__flashCircuitPython()

Private slot to flash a CircuitPython firmware to a device supporting UF2.

#### CircuitPythonDevice.__installLibraryFiles

__installLibraryFiles(packageMode=False)

Private slot to install Python files into the onboard library.

packageMode (bool (optional))
  flag indicating to install a library package (defaults to False)

#### CircuitPythonDevice.__modifySettings

__modifySettings(changedEntries)

Private method to modify the 'settings.toml' file as of CircuitPython 8.0.0.

changedEntries (dict of {str: str})
  dictionary containing the TOML entries to be changed

Return:
  tuple containing a success flag and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.__resetDevice

__resetDevice()

Private slot to reset the connected device.

#### CircuitPythonDevice.__selectDeviceVolume

__selectDeviceVolume()

Private slot to select the mounted device volume, if it could not be found automatically.

#### CircuitPythonDevice.__showTeensyFlashInstructions

__showTeensyFlashInstructions()

Private slot to show a message box because Teensy does not support the UF2 bootloader yet.

#### CircuitPythonDevice.__startTeensyLoader

__startTeensyLoader()

Private slot to start the 'Teensy Loader' application.

Note: The application must be accessible via the application search path.

#### CircuitPythonDevice.activateBluetoothInterface

activateBluetoothInterface()

Public method to activate the Bluetooth interface.

Return:
  flag indicating the new state of the Bluetooth interface

Return Type:
  bool

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.addDeviceMenuEntries

addDeviceMenuEntries(menu)

Public method to add device specific entries to the given menu.

menu (QMenu)
  reference to the context menu

#### CircuitPythonDevice.canRunScript

canRunScript()

Public method to determine, if a script can be executed.

Return:
  tuple containing a flag indicating it is safe to start a Plotter and a reason why it cannot.

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.canStartFileManager

canStartFileManager()

Public method to determine, if a File Manager can be started.

Return:
  tuple containing a flag indicating it is safe to start a File Manager and a reason why it cannot.

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.canStartPlotter

canStartPlotter()

Public method to determine, if a Plotter can be started.

Return:
  tuple containing a flag indicating it is safe to start a Plotter and a reason why it cannot.

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.canStartRepl

canStartRepl()

Public method to determine, if a REPL can be started.

Return:
  tuple containing a flag indicating it is safe to start a REPL and a reason why it cannot.

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.checkInternet

checkInternet()

Public method to check, if the internet can be reached.

Return:
  tuple containing a flag indicating reachability and an error string

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.checkInternetViaLan

checkInternetViaLan()

Public method to check, if the internet can be reached (LAN variant).

Return:
  tuple containing a flag indicating reachability and an error string

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.connectToLan

connectToLan(config, hostname)

Public method to connect the connected device to the LAN.

Note: The MAC address of the interface is configured with the WIZ

config (str or tuple of (str, str, str, str))
  configuration for the connection (either the string 'dhcp' for a dynamic address or a tuple of four strings with the IPv4 parameters.
hostname (str)
  host name of the device

Return:
  tuple containing a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.connectWifi

connectWifi(ssid, password, hostname, country="")

Public method to connect a device to a WiFi network.

ssid (str)
  name (SSID) of the WiFi network
password (str)
  password needed to connect
hostname (str)
  host name of the device
country (str)
  WiFi country code

Return:
  tuple containing the connection status and an error string

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.deactivateBluetoothInterface

deactivateBluetoothInterface()

Public method to deactivate the Bluetooth interface.

Return:
  flag indicating the new state of the Bluetooth interface

Return Type:
  bool

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.deactivateEthernet

deactivateEthernet()

Public method to deactivate the Ethernet interface of the connected device.

Return:
  tuple containg a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.deactivateInterface

deactivateInterface(interface)

Public method to deactivate a given WiFi interface of the connected device.

Note: With CircuitPython it is not possible to deactivate the station and access point interfaces separately.

interface (str)
  designation of the interface to be deactivated (one of 'AP' or 'STA')

Return:
  tuple containg a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

Raises ValueError:
  raised to indicate a wrong value for the interface type

#### CircuitPythonDevice.deviceName

deviceName()

Public method to get the name of the device.

Return:
  name of the device

Return Type:
  str

#### CircuitPythonDevice.disconnectFromLan

disconnectFromLan()

Public method to disconnect from the LAN.

Return:
  tuple containing a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.disconnectWifi

disconnectWifi()

Public method to disconnect a device from the WiFi network.

Return:
  tuple containing a flag indicating success and an error string

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.forceInterrupt

forceInterrupt()

Public method to determine the need for an interrupt when opening the serial connection.

Return:
  flag indicating an interrupt is needed

Return Type:
  bool

#### CircuitPythonDevice.getBluetoothStatus

getBluetoothStatus()

Public method to get Bluetooth status data of the connected board.

Return:
  list of tuples containing the translated status data label and the associated value

Return Type:
  list of tuples of (str, str)

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.getConnectedClients

getConnectedClients()

Public method to get a list of connected clients.

Return:
  a tuple containing a list of tuples containing the client MAC-Address and the RSSI (if supported and available) and an error message

Return Type:
  tuple of ([(bytes, int)], str)

#### CircuitPythonDevice.getDeviceScan

getDeviceScan(timeout=10)

Public method to perform a Bluetooth device scan.

timeout (int (optional))
  duration of the device scan in seconds (defaults to 10)

Return:
  tuple containing a dictionary with the scan results and an error string

Return Type:
  tuple of (dict, str)

#### CircuitPythonDevice.getDocumentationUrl

getDocumentationUrl()

Public method to get the device documentation URL.

Return:
  documentation URL of the device

Return Type:
  str

#### CircuitPythonDevice.getDownloadMenuEntries

getDownloadMenuEntries()

Public method to retrieve the entries for the downloads menu.

Return:
  list of tuples with menu text and URL to be opened for each entry

Return Type:
  list of tuple of (str, str)

#### CircuitPythonDevice.getEthernetStatus

getEthernetStatus()

Public method to get Ethernet status data of the connected board.

Return:
  list of tuples containing the translated status data label and the associated value and a dictionary with keys 'ipv4' and 'ipv6' containing the respective address information

Return Type:
  tuple of list of tuples of (str, str) and dict

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.getSecurityModes

getSecurityModes()

Public method to get a list of security modes supported by the device.

Return:
  list of supported security modes

Return Type:
  list of str

#### CircuitPythonDevice.getWifiData

getWifiData()

Public method to get data related to the current WiFi status.

Return:
  tuple of three dictionaries containing the WiFi status data for the WiFi client, access point and overall data

Return Type:
  tuple of (dict, dict, dict)

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.getWorkspace

getWorkspace(silent=False)

Public method to get the workspace directory.

silent (bool)
  flag indicating silent operations

Return:
  workspace directory used for saving files

Return Type:
  str

#### CircuitPythonDevice.hasBluetooth

hasBluetooth()

Public method to check the availability of Bluetooth.

Return:
  flag indicating the availability of Bluetooth

Return Type:
  bool

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.hasEthernet

hasEthernet()

Public method to check the availability of Ethernet.

Return:
  tuple containing a flag indicating the availability of Ethernet and the Ethernet type

Return Type:
  tuple of (bool, str)

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.hasFlashMenuEntry

hasFlashMenuEntry()

Public method to check, if the device has its own flash menu entry.

Return:
  flag indicating a specific flash menu entry

Return Type:
  bool

#### CircuitPythonDevice.hasNetworkTime

hasNetworkTime()

Public method to check the availability of network time functions.

Return:
  flag indicating the availability of network time functions

Return Type:
  bool

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.hasWifi

hasWifi()

Public method to check the availability of WiFi.

Return:
  tuple containing a flag indicating the availability of WiFi and the WiFi type (circuitpython)

Return Type:
  tuple of (bool, str)

Raises OSError:
  raised to indicate an issue with the device

#### CircuitPythonDevice.isLanConnected

isLanConnected()

Public method to check the LAN connection status.

Return:
  flag indicating that the device is connected to the LAN

Return Type:
  bool

#### CircuitPythonDevice.isWifiApConnected

isWifiApConnected()

Public method to check the WiFi connection status as access point.

Return:
  flag indicating the WiFi connection status

Return Type:
  bool

#### CircuitPythonDevice.isWifiClientConnected

isWifiClientConnected()

Public method to check the WiFi connection status as client.

Return:
  flag indicating the WiFi connection status

Return Type:
  bool

#### CircuitPythonDevice.removeCredentials

removeCredentials()

Public method to remove the saved credentials from the connected device.

Return:
  tuple containing a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.removeLanAutoConnect

removeLanAutoConnect()

Public method to remove the saved IPv4 parameters from the connected device.

Note: This disables the LAN auto-connect feature.

Return:
  tuple containing a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.runScript

runScript(script)

Public method to run the given Python script.

script (str)
  script to be executed

#### CircuitPythonDevice.scanNetworks

scanNetworks()

Public method to scan for available WiFi networks.

Return:
  tuple containing the list of available networks as a tuple of 'Name', 'MAC-Address', 'channel', 'RSSI' and 'security' and an error string

Return Type:
  tuple of (list of tuple of (str, str, int, int, str), str)

#### CircuitPythonDevice.setButtons

setButtons()

Public method to enable the supported action buttons.

#### CircuitPythonDevice.setConnected

setConnected(connected)

Public method to set the connection state.

connected (bool)
  connection state

#### CircuitPythonDevice.setNetworkTime

setNetworkTime(server="0.pool.ntp.org", tzOffset=0, timeout=10)

Public method to set the time to the network time retrieved from an NTP server.

server (str (optional))
  name of the NTP server to get the network time from (defaults to "0.pool.ntp.org")
tzOffset (int (optional))
  offset with respect to UTC (defaults to 0)
timeout (int)
  maximum time to wait for a server response in seconds (defaults to 10)

Return:
  tuple containing a flag indicating success and an error string

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.setWorkspace

setWorkspace(workspacePath)

Public method to set the device workspace directory.

workspacePath (str)
  directory to be used for saving files

#### CircuitPythonDevice.showCircuitPythonVersions

showCircuitPythonVersions()

Public slot to show the CircuitPython version of a connected device and the latest available one (from Github).

#### CircuitPythonDevice.startAccessPoint

startAccessPoint(ssid, security=None, password=None, hostname=None, ifconfig=None, )

Public method to start the access point interface.

ssid (str)
  SSID of the access point
security (str (optional))
  security mode (defaults to None) (unused)
password (str (optional))
  password (defaults to None)
hostname (str (optional))
  host name of the device (defaults to None)
ifconfig (tuple of (str, str, str, str))
  IPv4 configuration for the access point if not default (IPv4 address, netmask, gateway address, DNS server address)

Return:
  tuple containing a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.stopAccessPoint

stopAccessPoint()

Public method to stop the access point interface.

Return:
  tuple containg a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.supportsDeviceScan

supportsDeviceScan()

Public method to indicate, that the Bluetooth implementation supports scanning for devices.

Return:
  flag indicating that the scanning function is supported

Return Type:
  bool

#### CircuitPythonDevice.supportsLocalFileAccess

supportsLocalFileAccess()

Public method to indicate file access via a local directory.

Return:
  flag indicating file access via local directory

Return Type:
  bool

#### CircuitPythonDevice.writeCredentials

writeCredentials(ssid, password, hostname, _country)

Public method to write the given credentials to the connected device and modify the start script to connect automatically.

ssid (str)
  SSID of the network to connect to
password (str)
  password needed to authenticate
hostname (str)
  host name of the device
_country (str)
  WiFi country code (unused)

Return:
  tuple containing a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

#### CircuitPythonDevice.writeLanAutoConnect

writeLanAutoConnect(config, hostname)

Public method to generate a script and associated configuration to connect the device to the LAN during boot time.

config (str or tuple of (str, str, str, str))
  configuration for the connection (either the string 'dhcp' for a dynamic address or a tuple of four strings with the IPv4 parameters.
hostname (str)
  host name of the device

Return:
  tuple containing a flag indicating success and an error message

Return Type:
  tuple of (bool, str)

Up

## createDevice

createDevice(microPythonWidget, deviceType, vid, pid, boardName, _serialNumber)

Function to instantiate a MicroPython device object.

microPythonWidget (MicroPythonWidget)
  reference to the main MicroPython widget
deviceType (str)
  device type assigned to this device interface
vid (int)
  vendor ID
pid (int)
  product ID
boardName (str)
  name of the board
_serialNumber (str)
  serial number of the board (unused)

Return:
  reference to the instantiated device object

Return Type:
  CircuitPythonDevice

Up